package com.github.bridge.controller;

import com.github.bridge.annotation.SysLog;
import com.github.bridge.handler.BridgeHandler;
import com.github.bridge.request.*;
import com.github.bridge.response.*;
import com.github.bridge.util.R;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.timevale.esign.paas.tech.bean.request.QueryAccountInfoParam;
import com.timevale.esign.paas.tech.bean.result.AccountInfoResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/outer")
@RequiredArgsConstructor
@Tag(name = "外部机构用户等")
@ApiSupport(order = 2, author = "张辉")
public class OuterController {
    private final BridgeHandler bridgeHandler;

    @PostMapping("/createOrg")
    @Operation(summary = "创建外部机构")
    @SysLog(value = "创建外部机构")
//    @Log(value = "创建外部机构", position = Position.ENABLED, readWriteType = ReadWriteType.WRITE)
    public R<CreateOuterOrgVO> createOuterOrg(@RequestBody @Validated CreateOuterOrgDTO dto) {
        CreateOuterOrgVO vo = bridgeHandler.createOuterOrg(dto);
        return R.ok(vo);
    }

    @PostMapping("/createUser")
    @Operation(summary = "创建外部用户")
    @SysLog(value = "创建外部用户")
//    @Log(value = "创建外部用户", position = Position.ENABLED, readWriteType = ReadWriteType.WRITE)
    public R<CreateOuterUserVO> createOuterUser(@RequestBody @Validated CreateOuterUserDTO dto) {
        CreateOuterUserVO vo = bridgeHandler.createOuterUser(dto);
        return R.ok(vo);
    }

    @PostMapping("/deleteOuterUser")
    @Operation(summary = "注销外部用户(慎用)")
    @SysLog(value = "注销外部用户")
//    @Log(value = "注销外部用户", position = Position.ENABLED, readWriteType = ReadWriteType.WRITE)
    public R<BaseVO> deleteOuterUser(@RequestBody @Validated DeleteOuterUserDTO dto) {
        BaseVO vo = bridgeHandler.deleteOuterUser(dto);
        return R.ok(vo);
    }

    @PostMapping("/createOrgSeal")
    @Operation(summary = "创建外部企业模板印章")
    @SysLog(value = "创建外部企业模板印章")
//    @Log(value = "创建外部企业模板印章", position = Position.ENABLED, readWriteType = ReadWriteType.WRITE)
    public R<CreateOuterOrgSealVO> createOuterOrgSeal(@RequestBody @Validated CreateOuterOrgSealDTO dto) {
        CreateOuterOrgSealVO vo = bridgeHandler.createOuterOrgSeal(dto);
        return R.ok(vo);
    }

    @PostMapping("/createUserSeal")
    @Operation(summary = "创建外部用户模板印章")
    @SysLog(value = "创建外部用户模板印章")
//    @Log(value = "创建外部用户模板印章", position = Position.ENABLED, readWriteType = ReadWriteType.WRITE)
    public R<CreateOuterUserSealVO> createOuterUserSeal(@RequestBody @Validated CreateOuterUserSealDTO dto) {
        CreateOuterUserSealVO vo = bridgeHandler.createOuterUserSeal(dto);
        return R.ok(vo);
    }

    @PostMapping("/createUserAndSeal")
    @Operation(summary = "创建外部用户和印章")
    @SysLog(value = "创建外部用户和印章")
//    @Log(value = "创建外部用户和印章", position = Position.ENABLED, readWriteType = ReadWriteType.WRITE)
    public R<CreateUserAndSealVO> createUserAndSeal(@RequestBody @Validated CreateUserAndSealDTO dto) {
        CreateUserAndSealVO vo = bridgeHandler.createUserAndSeal(dto);
        return R.ok(vo);
    }

    @PostMapping("/createOrgAndSeal")
    @Operation(summary = "创建外部机构和印章")
    @SysLog(value = "创建外部机构和印章")
//    @Log(value = "创建外部机构和印章", position = Position.ENABLED, readWriteType = ReadWriteType.WRITE)
    public R<CreateOrgAndSealVO> createOrgAndSeal(@RequestBody @Validated CreateOrgAndSealDTO dto) {
        CreateOrgAndSealVO vo = bridgeHandler.createOrgAndSeal(dto);
        return R.ok(vo);
    }

    @PostMapping("/getAccountInfo")
    @Operation(summary = "获取账号信息")
    public R<AccountInfoResult> getAccountInfo(@RequestBody @Validated QueryAccountInfoParam dto) {
        return R.ok(bridgeHandler.getAccountInfo(dto));
    }

}


